//
//  ViewController.m
//  IOS-frameAnim
//
//  Created by RIOS on 2018/3/30.
//  Copyright © 2018年 RIOS. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image;
- (IBAction)btnLeft:(id)sender;
- (IBAction)btnRight:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;

@property (strong,nonatomic) NSArray *picture;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self initial];
}

- (void) initial{
    self.label1.text = @"1/7";
    self.label2.text = @"初始";
    [self.image setImage:[UIImage imageNamed:@"image0"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray *)picture{
    if ( _picture == nil) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"image.plist" ofType:nil];
        _picture = [NSArray arrayWithContentsOfFile:path];
        NSLog(@"array:%@",_picture);
        
    }
    return _picture;
}

- (IBAction)btnLeft:(id)sender {
    
    int index = [[self.label1.text substringWithRange:NSMakeRange(0, 1)] intValue];
    NSLog(@"index:%d",index);
    if (1 < index) {
        index--;
        self.label1.text = [NSString stringWithFormat:@"%d/7",index];
        NSDictionary *dict =  self.picture[index-1];
        self.label2.text = dict[@"label"];
        self.image.image = [UIImage imageNamed:dict[@"icon"]];
    }else{
        
    }
    
}

- (IBAction)btnRight:(id)sender {
    int index = [[self.label1.text substringFromIndex:0] intValue];
    NSLog(@"index:%d",index);
    if (index<7) {
        index++;
        self.label1.text = [NSString stringWithFormat:@"%d/7",index];
        NSDictionary *dict =  self.picture[index-1];
        self.label2.text = dict[@"label"];
        self.image.image = [UIImage imageNamed:dict[@"icon"]];
    }else{
        
    }
}
@end
